package app.sb.jly.com.ji_liang_yuan.activitys.ac;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoImpl;
import com.jph.takephoto.model.CropOptions;
import com.jph.takephoto.model.InvokeParam;
import com.jph.takephoto.model.TContextWrap;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.permission.InvokeListener;
import com.jph.takephoto.permission.PermissionManager;
import com.jph.takephoto.permission.TakePhotoInvocationHandler;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import app.sb.jly.com.ji_liang_yuan.R;
import app.sb.jly.com.ji_liang_yuan.activitys.application.BaseApplication;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.Base64Util;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.CommonUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.DateUtil;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.PDALogUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.UtilsLog;
import app.sb.jly.com.ji_liang_yuan.activitys.commons.ZXingUtils;
import app.sb.jly.com.ji_liang_yuan.activitys.ocr.FileUtil;
import app.sb.jly.com.ji_liang_yuan.activitys.ocr.HttpUtil;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static app.sb.jly.com.ji_liang_yuan.activitys.commons.Constants.che_liang_zhun_que_deng_ji;

public class ShuJuJISuan2Activity extends BaseActivity implements TakePhoto.TakeResultListener, InvokeListener {

    @BindView(R.id.ac_ac_shuju2_2_et_di_1)
    EditText acShuju2_2_EtDi1;
    @BindView(R.id.ac_ac_shuju2_2_iv_di_1)
    ImageView acShuju2_2_IvDi1;
    @BindView(R.id.ac_ac_shuju2_2_et_di_2)
    EditText acShuju2_2_EtDi2;
    @BindView(R.id.ac_ac_shuju2_2_iv_di_2)
    ImageView acShuju2_2_IvDi2;
    @BindView(R.id.ac_ac_shuju2_222_et_zhong_1)
    EditText acShuju2_2_EtZhong1;
    @BindView(R.id.ac_ac_shuju2_2_iv_zhong_1)
    ImageView acShuju2_2_IvZhong1;
    @BindView(R.id.ac_ac_shuju2_2_et_zhong_2)
    EditText acShuju2_2_EtZhong2;
    @BindView(R.id.ac_ac_shuju2_2_iv_zhong_2)
    ImageView acShuju2_2_IvZhong2;
    @BindView(R.id.ac_ac_shuju2_2_et_gao_1)
    EditText acShuju2_2_EtGao1;
    @BindView(R.id.ac_ac_shuju2_2_iv_gao_1)
    ImageView acShuju2_2_IvGao1;
    @BindView(R.id.ac_ac_shuju2_2_et_gao_2)
    EditText acShuju2_2_EtGao2;
    @BindView(R.id.ac_ac_shuju2_2_iv_gao_2)
    ImageView acShuju2_2_IvGao2;
    @BindView(R.id.ac_ac_shuju2_2_et_zuo_1)
    EditText acShuju2_2_EtZuo1;
    @BindView(R.id.ac_ac_shuju2_2_iv_zuo_1)
    ImageView acShuju2_2_IvZuo1;
    @BindView(R.id.ac_ac_shuju2_2_et_zuo_2)
    EditText acShuju2_2_EtZuo2;
    @BindView(R.id.ac_ac_shuju2_2_iv_zuo_2)
    ImageView acShuju2_2_IvZuo2;
    @BindView(R.id.ac_ac_shuju2_2_et_you_1)
    EditText acShuju2_2_EtYou1;
    @BindView(R.id.ac_ac_shuju2_2_iv_you_1)
    ImageView acShuju2_2_IvYou1;
    @BindView(R.id.ac_ac_shuju2_2_et_you_2)
    EditText acShuju2_2_EtYou2;
    @BindView(R.id.ac_ac_shuju2_2_iv_you_2)
    ImageView acShuju2_2_IvYou2;
    @BindView(R.id.ac_ac_shuju2_2_et_zuida_wucha)
    EditText acShuju2_2_EtZuidaWucha;
    @BindView(R.id.ac_ac_mpe_shuju2_2_et_mpe)
    EditText acShuju2_2_EtMpe;
    @BindView(R.id.ac_shuju2_2_btn_next)
    Button acShuju2_2_BtnNext;
    @BindView(R.id.ac_shuju2_2_btn_back)
    Button acShuju2_2_BtnBack;
    @BindView(R.id.ac_shuju2_2_btn_check)
    Button acShuju2BtnCheck;

    public ShuJuJISuan2Activity instances = null;
    String access_token = "";
    EditText currentET = null;
    int in_type = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getTakePhoto().onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shu_ju_jisuan2);
        ButterKnife.bind(this);
        instances = this;
        in_type = getIntent().getIntExtra("in_type", 0);
        UtilsLog.e("in_type=======" + in_type);
        setTopTitle("数据计算");
        setLeftTxt("返回", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ShuJuJISuan2Activity.this, ShuJuJISuanActivity.class);
                setResult(RESULT_OK, intent);
                finish();
            }
        });

    }

    @OnClick({R.id.ac_ac_shuju2_2_iv_di_1, R.id.ac_ac_shuju2_2_iv_di_2,
            R.id.ac_ac_shuju2_2_iv_zhong_1, R.id.ac_ac_shuju2_2_iv_zhong_2,
            R.id.ac_ac_shuju2_2_iv_gao_1, R.id.ac_ac_shuju2_2_iv_gao_2,
            R.id.ac_ac_shuju2_2_iv_zuo_1, R.id.ac_ac_shuju2_2_iv_zuo_2,
            R.id.ac_ac_shuju2_2_iv_you_1, R.id.ac_ac_shuju2_2_iv_you_2,
            R.id.ac_shuju2_2_btn_next, R.id.ac_shuju2_2_btn_back,
            R.id.ac_shuju2_2_btn_check})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_ac_shuju2_2_iv_di_1:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtDi1;
                break;
            case R.id.ac_ac_shuju2_2_iv_di_2:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtDi2;
                break;
            case R.id.ac_ac_shuju2_2_iv_zhong_1:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtZhong1;
                break;
            case R.id.ac_ac_shuju2_2_iv_zhong_2:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtZhong2;
                break;
            case R.id.ac_ac_shuju2_2_iv_gao_1:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtGao1;
                break;
            case R.id.ac_ac_shuju2_2_iv_gao_2:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtGao2;
                break;
            case R.id.ac_ac_shuju2_2_iv_zuo_1:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtZuo1;
                break;
            case R.id.ac_ac_shuju2_2_iv_zuo_2:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtZuo2;
                break;
            case R.id.ac_ac_shuju2_2_iv_you_1:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtYou1;
                break;
            case R.id.ac_ac_shuju2_2_iv_you_2:
                getToken();
                gotoRoadTakePhoto();
                currentET = acShuju2_2_EtYou2;
                break;
            case R.id.ac_shuju2_2_btn_next:
                //第二次采集
                setJiSuanData();
//                if (in_type != 3) {
//                    finish();
//                } else {
//                    Intent intent = new Intent(instances, ShuJuJISuan2Activity.class);
//                    startActivity(intent);
//                    finish();
//                }
//                if(in_type==3){
//                    Intent intent = new Intent(instances, ShuJuJISuan2Activity.class);
//                    startActivity(intent);
////                    finish();
//                }

                break;
            case R.id.ac_shuju2_2_btn_back:
                //返回
                //生成报表
                String EtDi1 = acShuju2_2_EtDi1.getText().toString().trim();
                String EtDi2 = acShuju2_2_EtDi2.getText().toString().trim();
                String EtZhong1 = acShuju2_2_EtZhong1.getText().toString().trim();
                String EtZhong2 = acShuju2_2_EtZhong2.getText().toString().trim();
                String EtGao1 = acShuju2_2_EtGao1.getText().toString().trim();
                String EtGao2 = acShuju2_2_EtGao2.getText().toString().trim();
                String EtZuo1 = acShuju2_2_EtZuo1.getText().toString().trim();
                String EtZuo2 = acShuju2_2_EtZuo2.getText().toString().trim();
                String EtYou1 = acShuju2_2_EtYou1.getText().toString().trim();
                String EtYou2 = acShuju2_2_EtYou2.getText().toString().trim();
                String EtMaxMistic = acShuju2_2_EtZuidaWucha.getText().toString().trim();
                String Mpe = acShuju2_2_EtMpe.getText().toString().trim();
                if (checkeData(EtDi1) && checkeData(EtDi2) &&
                        checkeData(EtZhong1) && checkeData(EtZhong2) &&
                        checkeData(EtGao1) && checkeData(EtGao2) &&
                        checkeData(EtZuo1) && checkeData(EtZuo2) &&
                        checkeData(EtYou1) && checkeData(EtYou2) &&
                        checkeData(EtMaxMistic) && checkeData(Mpe)) {
                    if (BaseApplication.myCheckDataModel != null) {
                        setTxtContents(BaseApplication.myCheckDataModel.getTxt_name());
                        //生成后清空单元格
//                        acShuju2_2_EtDi1.setText("");
//                        acShuju2_2_EtDi2.setText("");
//                        acShuju2_2_EtZhong1.setText("");
//                        acShuju2_2_EtZhong2.setText("");
//                        acShuju2_2_EtGao1.setText("");
//                        acShuju2_2_EtGao2.setText("");
//                        acShuju2_2_EtZuo1.setText("");
//                        acShuju2_2_EtZuo2.setText("");
//                        acShuju2_2_EtYou1.setText("");
//                        acShuju2_2_EtYou2.setText("");
//                        acShuju2_2_EtZuidaWucha.setText("");
//                        acShuju2_2_EtMpe.setText("");
                    }
                } else {
                    AlertDialog dialog = new AlertDialog.Builder(this)
                            .setTitle("生成报表")
                            .setMessage("请确认已完成数据采集及计算，即将生成报表？")
                            .setPositiveButton("是", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    String EtDi1 = TextUtils.isEmpty(acShuju2_2_EtDi1.getText().toString().trim()) ? "0" : acShuju2_2_EtDi1.getText().toString().trim();
                                    String EtDi2 = TextUtils.isEmpty(acShuju2_2_EtDi2.getText().toString().trim()) ? "0" : acShuju2_2_EtDi2.getText().toString().trim();
                                    String EtZhong1 = TextUtils.isEmpty(acShuju2_2_EtZhong1.getText().toString().trim()) ? "0" : acShuju2_2_EtZhong1.getText().toString().trim();
                                    String EtZhong2 = TextUtils.isEmpty(acShuju2_2_EtZhong2.getText().toString().trim()) ? "0" : acShuju2_2_EtZhong2.getText().toString().trim();
                                    String EtGao1 = TextUtils.isEmpty(acShuju2_2_EtGao1.getText().toString().trim()) ? "0" : acShuju2_2_EtGao1.getText().toString().trim();
                                    String EtGao2 = TextUtils.isEmpty(acShuju2_2_EtGao2.getText().toString().trim()) ? "0" : acShuju2_2_EtGao2.getText().toString().trim();
                                    String EtZuo1 = TextUtils.isEmpty(acShuju2_2_EtZuo1.getText().toString().trim()) ? "0" : acShuju2_2_EtZuo1.getText().toString().trim();
                                    String EtZuo2 = TextUtils.isEmpty(acShuju2_2_EtZuo2.getText().toString().trim()) ? "0" : acShuju2_2_EtZuo2.getText().toString().trim();
                                    String EtYou1 = TextUtils.isEmpty(acShuju2_2_EtYou1.getText().toString().trim()) ? "0" : acShuju2_2_EtYou1.getText().toString().trim();
                                    String EtYou2 = TextUtils.isEmpty(acShuju2_2_EtYou2.getText().toString().trim()) ? "0" : acShuju2_2_EtYou2.getText().toString().trim();
                                    //最大误差计算
                                    String[] values = {EtDi1, EtDi2, EtZhong1, EtZhong2,
                                            EtGao1, EtGao2, EtZuo1, EtZuo2,
                                            EtYou1, EtYou2};
//                                    int myMax = getMaxValue(values);
//                                    int myMin = getMinValue(values);
                                    int car_weight = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getZhongliang1()) ?
                                            Integer.valueOf(BaseApplication.myCheckDataModel.getZhongliang1()) : 0;
//                                    int zui_da_wu_cha = Math.max(myMax - car_weight, myMin - car_weight);
                                    int zui_da_wu_cha = getMaxMistake(values, car_weight);
                                    UtilsLog.e("zui_da_wu_cha===" + zui_da_wu_cha);
                                    acShuju2_2_EtZuidaWucha.setText(String.valueOf(zui_da_wu_cha));
                                    //MPE计算

                                    acShuju2_2_EtMpe.setText(getMPE());


                                    String ZuidaWucha = acShuju2_2_EtZuidaWucha.getText().toString().trim();
                                    String mpe = acShuju2_2_EtMpe.getText().toString().trim();

                                    BaseApplication.myCheckDataModel.setDisuzhongxin10(EtDi1);
                                    BaseApplication.myCheckDataModel.setDisuzhongxin11(EtDi2);
                                    BaseApplication.myCheckDataModel.setZhongsuzhognxin10(EtZhong1);
                                    BaseApplication.myCheckDataModel.setZhongsuzhognxin11(EtZhong2);
                                    BaseApplication.myCheckDataModel.setGaosuzhognxin10(EtGao1);
                                    BaseApplication.myCheckDataModel.setGaosuzhognxin11(EtGao2);
                                    BaseApplication.myCheckDataModel.setDisupianzuo10(EtZuo1);
                                    BaseApplication.myCheckDataModel.setDisupianzuo11(EtZuo2);
                                    BaseApplication.myCheckDataModel.setDisupianyou10(EtYou1);
                                    BaseApplication.myCheckDataModel.setDisupianyou11(EtYou2);
                                    BaseApplication.myCheckDataModel.setZuidawucha2(ZuidaWucha);
                                    BaseApplication.myCheckDataModel.setMPE2(mpe);

                                    int z = Math.abs(Integer.valueOf(ZuidaWucha));
                                    int m = Math.abs(Integer.valueOf(mpe));
                                    if (z <= m) {
                                        BaseApplication.myCheckDataModel.setHege2("合格");
                                    } else if (z > m) {
                                        BaseApplication.myCheckDataModel.setHege2("不合格");
                                    }
                                    if (BaseApplication.myCheckDataModel != null) {
                                        setTxtContents(BaseApplication.myCheckDataModel.getTxt_name());
                                        //生成后清空单元格
//                                        acShuju2_2_EtDi1.setText("");
//                                        acShuju2_2_EtDi2.setText("");
//                                        acShuju2_2_EtZhong1.setText("");
//                                        acShuju2_2_EtZhong2.setText("");
//                                        acShuju2_2_EtGao1.setText("");
//                                        acShuju2_2_EtGao2.setText("");
//                                        acShuju2_2_EtZuo1.setText("");
//                                        acShuju2_2_EtZuo2.setText("");
//                                        acShuju2_2_EtYou1.setText("");
//                                        acShuju2_2_EtYou2.setText("");
//                                        acShuju2_2_EtZuidaWucha.setText("");
//                                        acShuju2_2_EtMpe.setText("");
                                    }
//                                    moreClose = false;
                                    dialog.dismiss();
                                    Intent intent2 = new Intent(ShuJuJISuan2Activity.this, ShuJuJISuanActivity.class);
                                    setResult(RESULT_OK, intent2);
//                                    finish();
                                }
                            })
                            .setNegativeButton("否", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
//                                    moreClose = true;
                                    dialog.dismiss();
                                }
                            }).create();
                    dialog.show();
                }
                break;
            case R.id.ac_shuju2_2_btn_check:
                //下一车型
                break;
        }
    }

    void setTxtContents(String fileName) {
        String str = "";
//        for (int i = 0; i < Constants.contents.length; i++) {
//            str += Constants.contents[i] + "\r\n";
//        }
//        UtilsLog.e(str);

        if (BaseApplication.myCheckDataModel == null) {
            return;
        }
        //多轴刚性和铰接挂车
//        if (BaseApplication.myCheckDataModel.getType0().equals("多轴刚性")
//                || BaseApplication.myCheckDataModel.getType0().equals("铰接挂车")) {
//            str = BaseApplication.myCheckDataModel.getSongjiandaiwei() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getJiandingdidian() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getWendu() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhidaodanwei() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getJiliangqijumingcheng() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getXinhaoguige() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getFenduzhi() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getZuidachengliang() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuixiaochengliang() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getDengji() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getZuigaosudu() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuidisudu() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getType0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhoushu0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongliang0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuidawucha1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getMPE1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getHege1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getUname() + "\r\n"
//            ;
//        } else {
//            str = BaseApplication.myCheckDataModel.getSongjiandaiwei() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getJiandingdidian() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getWendu() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhidaodanwei() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getJiliangqijumingcheng() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getXinhaoguige() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getFenduzhi() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getZuidachengliang() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuixiaochengliang() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getDengji() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getZuigaosudu() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuidisudu() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getShijian() + "\r\n"
//
//                    + BaseApplication.myCheckDataModel.getType0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhoushu0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongliang0() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou00() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou01() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuidawucha1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getMPE1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getHege1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getType1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhoushu1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongliang1() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin10() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisuzhongxin11() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin10() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZhongsuzhognxin11() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin10() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getGaosuzhognxin11() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo10() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianzuo11() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou10() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getDisupianyou11() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getZuidawucha2() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getMPE2() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getHege2() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getUname() + "\r\n"
//            ;
//        }

        //多轴刚性和铰接挂车 in_type = 3
        str = BaseApplication.myCheckDataModel.getSongjiandaiwei() + "\r\n"
                + BaseApplication.myCheckDataModel.getJiandingdidian() + "\r\n"
                + BaseApplication.myCheckDataModel.getWendu() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhidaodanwei() + "\r\n"
                + BaseApplication.myCheckDataModel.getJiliangqijumingcheng() + "\r\n"
                + BaseApplication.myCheckDataModel.getXinhaoguige() + "\r\n"
                + BaseApplication.myCheckDataModel.getFenduzhi() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuidachengliang() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuixiaochengliang() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhizaoxukezhengbianhao() + "\r\n"
                + BaseApplication.myCheckDataModel.getChuchangbianhoa() + "\r\n"
                + BaseApplication.myCheckDataModel.getDengji() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuigaosudu() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuidisudu() + "\r\n"
                + BaseApplication.myCheckDataModel.getShijian() + "\r\n"
                + BaseApplication.myCheckDataModel.getYouxiaoqi() + "\r\n"
//                    + BaseApplication.myCheckDataModel.getType0() + "\r\n"
                + BaseApplication.myCheckDataModel.getWholeInfoA() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhoushu0() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongliang0() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisuzhongxin00() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisuzhongxin01() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongsuzhognxin00() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongsuzhognxin01() + "\r\n"
                + BaseApplication.myCheckDataModel.getGaosuzhognxin00() + "\r\n"
                + BaseApplication.myCheckDataModel.getGaosuzhognxin01() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianzuo00() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianzuo01() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianyou00() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianyou01() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuidawucha1() + "\r\n"
                + BaseApplication.myCheckDataModel.getMPE1() + "\r\n"
                + BaseApplication.myCheckDataModel.getHege1() + "\r\n"

                + "铰接挂车" + "\r\n"
                + BaseApplication.myCheckDataModel.getZhoushu1() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongliang1() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisuzhongxin10() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisuzhongxin11() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongsuzhognxin10() + "\r\n"
                + BaseApplication.myCheckDataModel.getZhongsuzhognxin11() + "\r\n"
                + BaseApplication.myCheckDataModel.getGaosuzhognxin10() + "\r\n"
                + BaseApplication.myCheckDataModel.getGaosuzhognxin11() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianzuo10() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianzuo11() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianyou10() + "\r\n"
                + BaseApplication.myCheckDataModel.getDisupianyou11() + "\r\n"
                + BaseApplication.myCheckDataModel.getZuidawucha2() + "\r\n"
                + BaseApplication.myCheckDataModel.getMPE2() + "\r\n"
                + BaseApplication.myCheckDataModel.getHege2() + "\r\n"

                + BaseApplication.myCheckDataModel.getUname() + "\r\n"
                + BaseApplication.myCheckDataModel.getCheckUser() + "\r\n";

        PDALogUtils.createTxtFile(fileName, str.getBytes(), instances);

        Toast.makeText(this, "生成报表成功", Toast.LENGTH_LONG).show();
        Bitmap bitmap = ZXingUtils.createQRCodeBitmap(str, 800, 800, "UTF-8", "H", "1", Color.BLACK, Color.WHITE);
        String imagePath = Environment.getExternalStorageDirectory() + "/PDA_TXT/" + fileName + "_" + DateUtil.currentTime3() + ".jpg";
        File imageFile = new File(imagePath);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(imageFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        if (bitmap == null) {
            Toast.makeText(instances, "二维码图片生成失败", Toast.LENGTH_LONG).show();
            return;
        }
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        try {
            fos.flush();
            fos.close();
//                    Toast.makeText(context, "图片保存在："+ imageFile.getAbsolutePath(), 0).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void setJiSuanData() {
        String EtDi1 = acShuju2_2_EtDi1.getText().toString().trim();
        String EtDi2 = acShuju2_2_EtDi2.getText().toString().trim();
        String EtZhong1 = acShuju2_2_EtZhong1.getText().toString().trim();
        String EtZhong2 = acShuju2_2_EtZhong2.getText().toString().trim();
        String EtGao1 = acShuju2_2_EtGao1.getText().toString().trim();
        String EtGao2 = acShuju2_2_EtGao2.getText().toString().trim();
        String EtZuo1 = acShuju2_2_EtZuo1.getText().toString().trim();
        String EtZuo2 = acShuju2_2_EtZuo2.getText().toString().trim();
        String EtYou1 = acShuju2_2_EtYou1.getText().toString().trim();
        String EtYou2 = acShuju2_2_EtYou2.getText().toString().trim();

        if (checkeData(EtDi1) && checkeData(EtDi2) &&
                checkeData(EtZhong1) && checkeData(EtZhong2) &&
                checkeData(EtGao1) && checkeData(EtGao2) &&
                checkeData(EtZuo1) && checkeData(EtZuo2) &&
                checkeData(EtYou1) && checkeData(EtYou2)
                ) {
            //最大误差计算
            String[] values = {EtDi1, EtDi2, EtZhong1, EtZhong2,
                    EtGao1, EtGao2, EtZuo1, EtZuo2,
                    EtYou1, EtYou2};
            int myMax = getMaxValue(values);
            int myMin = getMinValue(values);
            int car_weight = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getZhongliang1()) ?
                    Integer.valueOf(BaseApplication.myCheckDataModel.getZhongliang1()) : 0;
            int finalMax = myMax - car_weight;
            int finalMin = myMin - car_weight;
//            int zui_da_wu_cha = Math.max(myMax - car_weight, myMin - car_weight);
            int zui_da_wu_cha = getMaxMistake(values, car_weight);
            UtilsLog.e("zui_da_wu_cha===" + zui_da_wu_cha);
            acShuju2_2_EtZuidaWucha.setText(String.valueOf(zui_da_wu_cha));
            //MPE计算

            acShuju2_2_EtMpe.setText(getMPE());


            String ZuidaWucha = acShuju2_2_EtZuidaWucha.getText().toString().trim();
            String mpe = acShuju2_2_EtMpe.getText().toString().trim();
            UtilsLog.e("ZuidaWucha===" + ZuidaWucha);
            UtilsLog.e("mpe===" + mpe);
            BaseApplication.myCheckDataModel.setDisuzhongxin10(EtDi1);
            BaseApplication.myCheckDataModel.setDisuzhongxin11(EtDi2);
            BaseApplication.myCheckDataModel.setZhongsuzhognxin10(EtZhong1);
            BaseApplication.myCheckDataModel.setZhongsuzhognxin11(EtZhong2);
            BaseApplication.myCheckDataModel.setGaosuzhognxin10(EtGao1);
            BaseApplication.myCheckDataModel.setGaosuzhognxin11(EtGao2);
            BaseApplication.myCheckDataModel.setDisupianzuo10(EtZuo1);
            BaseApplication.myCheckDataModel.setDisupianzuo11(EtZuo2);
            BaseApplication.myCheckDataModel.setDisupianyou10(EtYou1);
            BaseApplication.myCheckDataModel.setDisupianyou11(EtYou2);
            BaseApplication.myCheckDataModel.setZuidawucha2(ZuidaWucha);
            BaseApplication.myCheckDataModel.setMPE2(mpe);

//            if (checkeData(ZuidaWucha) && checkeData(mpe)) {
            int z = Math.abs(Integer.valueOf(ZuidaWucha));
            int m = Math.abs(Integer.valueOf(mpe));
            UtilsLog.e("m===" + m);
            UtilsLog.e("z===" + z);
            if (z <= m) {
                BaseApplication.myCheckDataModel.setHege2("合格");
            } else if (z > m) {
                BaseApplication.myCheckDataModel.setHege2("不合格");
            }

//            Intent intent = new Intent(ShuJuJISuan2Activity.this, ShuJuJISuanActivity.class);
//            setResult(RESULT_OK,intent);
//            finish();
//            }
//            else {
//                TipDialog.show(instances, "数据格式不正确", TipDialog.TYPE.ERROR);
//            }
        } else {
            AlertDialog dialog = new AlertDialog.Builder(this)
                    .setTitle("提示")
                    .setMessage("数据采集尚未完成，是否继续？")
                    .setPositiveButton("是", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String EtDi1 = TextUtils.isEmpty(acShuju2_2_EtDi1.getText().toString().trim()) ? "0" : acShuju2_2_EtDi1.getText().toString().trim();
                            String EtDi2 = TextUtils.isEmpty(acShuju2_2_EtDi2.getText().toString().trim()) ? "0" : acShuju2_2_EtDi2.getText().toString().trim();
                            String EtZhong1 = TextUtils.isEmpty(acShuju2_2_EtZhong1.getText().toString().trim()) ? "0" : acShuju2_2_EtZhong1.getText().toString().trim();
                            String EtZhong2 = TextUtils.isEmpty(acShuju2_2_EtZhong2.getText().toString().trim()) ? "0" : acShuju2_2_EtZhong2.getText().toString().trim();
                            String EtGao1 = TextUtils.isEmpty(acShuju2_2_EtGao1.getText().toString().trim()) ? "0" : acShuju2_2_EtGao1.getText().toString().trim();
                            String EtGao2 = TextUtils.isEmpty(acShuju2_2_EtGao2.getText().toString().trim()) ? "0" : acShuju2_2_EtGao2.getText().toString().trim();
                            String EtZuo1 = TextUtils.isEmpty(acShuju2_2_EtZuo1.getText().toString().trim()) ? "0" : acShuju2_2_EtZuo1.getText().toString().trim();
                            String EtZuo2 = TextUtils.isEmpty(acShuju2_2_EtZuo2.getText().toString().trim()) ? "0" : acShuju2_2_EtZuo2.getText().toString().trim();
                            String EtYou1 = TextUtils.isEmpty(acShuju2_2_EtYou1.getText().toString().trim()) ? "0" : acShuju2_2_EtYou1.getText().toString().trim();
                            String EtYou2 = TextUtils.isEmpty(acShuju2_2_EtYou2.getText().toString().trim()) ? "0" : acShuju2_2_EtYou2.getText().toString().trim();
                            //最大误差计算
                            String[] values = {EtDi1, EtDi2, EtZhong1, EtZhong2,
                                    EtGao1, EtGao2, EtZuo1, EtZuo2,
                                    EtYou1, EtYou2};
//                            int myMax = getMaxValue(values);
//                            int myMin = getMinValue(values);
                            int car_weight = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getZhongliang1()) ?
                                    Integer.valueOf(BaseApplication.myCheckDataModel.getZhongliang1()) : 0;
//                            int zui_da_wu_cha = Math.max(myMax - car_weight, myMin - car_weight);
                            int zui_da_wu_cha = getMaxMistake(values, car_weight);
                            UtilsLog.e("zui_da_wu_cha===" + zui_da_wu_cha);
                            acShuju2_2_EtZuidaWucha.setText(String.valueOf(zui_da_wu_cha));
                            //MPE计算

                            acShuju2_2_EtMpe.setText(getMPE());


                            String ZuidaWucha = acShuju2_2_EtZuidaWucha.getText().toString().trim();
                            String mpe = acShuju2_2_EtMpe.getText().toString().trim();

                            BaseApplication.myCheckDataModel.setDisuzhongxin10(EtDi1);
                            BaseApplication.myCheckDataModel.setDisuzhongxin11(EtDi2);
                            BaseApplication.myCheckDataModel.setZhongsuzhognxin10(EtZhong1);
                            BaseApplication.myCheckDataModel.setZhongsuzhognxin11(EtZhong2);
                            BaseApplication.myCheckDataModel.setGaosuzhognxin10(EtGao1);
                            BaseApplication.myCheckDataModel.setGaosuzhognxin11(EtGao2);
                            BaseApplication.myCheckDataModel.setDisupianzuo10(EtZuo1);
                            BaseApplication.myCheckDataModel.setDisupianzuo11(EtZuo2);
                            BaseApplication.myCheckDataModel.setDisupianyou10(EtYou1);
                            BaseApplication.myCheckDataModel.setDisupianyou11(EtYou2);
                            BaseApplication.myCheckDataModel.setZuidawucha2(ZuidaWucha);
                            BaseApplication.myCheckDataModel.setMPE2(mpe);

                            int z = Math.abs(Integer.valueOf(ZuidaWucha));
                            int m = Math.abs(Integer.valueOf(mpe));
                            if (z <= m) {
                                BaseApplication.myCheckDataModel.setHege2("合格");
                            } else if (z > m) {
                                BaseApplication.myCheckDataModel.setHege2("不合格");
                            }
                            dialog.dismiss();
//                            Intent intent = new Intent(ShuJuJISuan2Activity.this, ShuJuJISuanActivity.class);
//                            setResult(RESULT_OK,intent);
//                            finish();
                        }
                    })
                    .setNegativeButton("否", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create();
            dialog.show();
//            TipDialog.show(instances, "数据不能为空", TipDialog.TYPE.ERROR);
        }

    }

    String getMPE() {
        String re = "";
//        车辆总重量准确度等级：为10级时t1=5%；为5级时t1=2.5%；为2级时t1=1%；为1级时t1=0.5%；为0.5级时t1=0.25%；为0.2级时t1=0.1%；
        String dengji = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getDengji()) ? BaseApplication.myCheckDataModel.getDengji() : "1级";
        double n = 0.005;
        if (che_liang_zhun_que_deng_ji[0].equals(dengji)) {
            n = 0.001;
        } else if (che_liang_zhun_que_deng_ji[1].equals(dengji)) {
            n = 0.0025;
        } else if (che_liang_zhun_que_deng_ji[2].equals(dengji)) {
            n = 0.005;
        } else if (che_liang_zhun_que_deng_ji[3].equals(dengji)) {
            n = 0.01;
        } else if (che_liang_zhun_que_deng_ji[4].equals(dengji)) {
            n = 0.025;
        } else if (che_liang_zhun_que_deng_ji[5].equals(dengji)) {
            n = 0.05;
        }
        String fenduzhi = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getFenduzhi()) ? BaseApplication.myCheckDataModel.getFenduzhi() : "20";
        String car_weight = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getZhongliang1()) ?
                BaseApplication.myCheckDataModel.getZhongliang1() : "0";
        double t1 = Double.valueOf(car_weight) * n;
        int d = Integer.valueOf(fenduzhi);
        UtilsLog.e("t1==" + t1);
        int i = (int) t1 % d;
        UtilsLog.e("i==" + i);
        int t2 = 0;
        if (i >= (d / 2)) {
            t2 = (int) t1 + d - i;
        } else if (i < (d / 2)) {
            t2 = (int) t1 - i;
        }
        int zhoushu = !TextUtils.isEmpty(BaseApplication.myCheckDataModel.getZhoushu1()) ? Integer.valueOf(BaseApplication.myCheckDataModel.getZhoushu1()) : 6;
        int t3 = d * zhoushu;
        re = String.valueOf(Math.max(Math.abs(t2), Math.abs(t3)));
        UtilsLog.e("getMPE===re==" + re);
        return re;
    }


    //检测字符串数值不为空,且是否为数字
    //false:空  true:不为空
    boolean checkeData(String str) {
        boolean re = false;
        if (!TextUtils.isEmpty(str) && !"".equals(str) && CommonUtils.isDigit(str)) {
            re = true;
        } else {
            re = false;
        }
        return re;
    }

    int getMaxValue(String[] values) {
        int max = 0;
        for (int i = 0; i < values.length; i++) {
            max = Math.max(max, Integer.valueOf(values[i]));
        }
        UtilsLog.e("最大值===" + max);
        return max;
    }

    int getMinValue(String[] values) {
        int min = 0;
        for (int i = 0; i < values.length; i++) {
            min = Math.min(min, Integer.valueOf(values[i]));
        }
        UtilsLog.e("最小值===" + min);
        return min;
    }

    int getMaxMistake(String[] values, int car_weight) {
        List<Integer> values2 = new ArrayList<>();
        for (String value : values) {
            values2.add(Integer.valueOf(value) - car_weight);
        }
        int outPut = values2.get(0);
        for (int i = 1; i < values2.size(); i++) {
            if (Math.abs(outPut) <= Math.abs(values2.get(i))) {
                outPut = values2.get(i);
            }
        }
        return outPut;
    }

    //获取车辆列表根据选择的检测类型
    private void getToken() {
        UtilsLog.e("getToken---url==" + getToken);
        OkGo.<String>get(getToken).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getToken-result=2=" + result);
                        String logStr = "\n" + "getToken--2---" + "\n"
                                + "\n" + "result==" + result + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        {
//                            "refresh_token": "25.b55fe1d287227ca97aab219bb249b8ab.315360000.1798284651.282335-8574074",
//                                "expires_in": 2592000,
//                                "scope": "public wise_adapt",
//                                "session_key": "9mzdDZXu3dENdFZQurfg0Vz8slgSgvvOAUebNFzyzcpQ5EnbxbF+hfG9DQkpUVQdh4p6HbQcAiz5RmuBAja1JJGgIdJI",
//                                "access_token": "24.6c5e1ff107f0e8bcef8c46d3424a0e78.2592000.1485516651.282335-8574074",
//                                "session_secret": "dfac94a3489fe9fca7c3221cbf7525ff"
//                        }
                        if (!TextUtils.isEmpty(result) && !"[[]]".equals(result) && !"[{}]".equals
                                (result) && !"[]".equals(result)) {
                            JSONObject jsonObject = null;
                            try {
                                jsonObject = new JSONObject(result);
                                access_token = jsonObject.getString("access_token");
                                UtilsLog.e("getToken-access_token==" + access_token);
                            } catch (JSONException e) {
                                e.printStackTrace();
                                UtilsLog.e("getToken-e==" + e.toString());
                                String logStr2 = "\n" + "getToken--2---" + "\n"
                                        + "\n" + "e==" + e.toString() + "\n";
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                            }
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getToken-onError=2=" + response.body());
                        String logStr = "\n" + "getToken--2---" + "\n"
                                + "\n" + "result" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }


    TakePhoto takePhoto;
    String photo_file_path_OriginalPath;

    public TakePhoto getTakePhoto() {
        Log.e("tag", "33333");
        if (takePhoto == null) {
            takePhoto = (TakePhoto) TakePhotoInvocationHandler.of(this).bind(new TakePhotoImpl(this, this));
        }
        return takePhoto;
    }

    @Override
    public void takeSuccess(TResult result) {
        Log.e("tag", "111111111111");
        if (result != null) {
            ArrayList<TImage> images = result.getImages();
            if (images != null && images.size() > 0) {
                //压缩后的图片路径，不压缩为null
                Log.e("tag", "拍照成功--path=111=" + images.get(0).getOriginalPath());
                Log.e("tag", "拍照成功--path=Environment=" + Environment.getExternalStorageDirectory());
                //拍照
                if (images.get(0).getOriginalPath().contains("storage/emulated")) {
                    photo_file_path_OriginalPath = images.get(0).getOriginalPath().replace("my_images/", "");
                } else {
                    photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
                            .getOriginalPath().replace("my_images/", "");
                }
//                    photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
//                            .getOriginalPath().replace("my_images/", "");
                Log.e("tag", "拍照成功--path=22=" + photo_file_path_OriginalPath);

                if (!TextUtils.isEmpty(photo_file_path_OriginalPath)) {


                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            webImage(photo_file_path_OriginalPath, access_token);
                        }
                    }).start();

//                    Luban.with(instances)
//                            .load(new File(photo_file_path_OriginalPath))                     //传人要压缩的图片
//                            .setCompressListener(new OnCompressListener() { //设置回调
//                                @Override
//                                public void onStart() {
//                                    // TODO 压缩开始前调用，可以在方法内启动 loading UI
//                                }
//
//                                @Override
//                                public void onSuccess(File file) {
//                                    // TODO 压缩成功后调用，返回压缩后的图片文件
//                                    Log.e("tag", "压缩成功后调用");
//                                    byte[] imgData = FileUtils.readFile(file);
//                                    String imgStr = Base64Util.encode(imgData);
//                                    try {
//                                        String imgParam= URLEncoder.encode(imgStr,"UTF-8");
//                                        UtilsLog.e("imgParam==="+imgParam);
//                                        String param = "image=" + imgParam;
//                                        webImage(imgData,access_token);
////                                        gotoOcr(param);
////                                        gotoOcr(imgParam);
//                                    } catch (UnsupportedEncodingException e) {
//                                        e.printStackTrace();
//                                    }
//                                    //拍照压缩后上传
////                                    getData(file,picFileFullName);
////                                        getDataUploadPhoto(file, photo_file_path_OriginalPath);
//                                }
//
//                                @Override
//                                public void onError(Throwable e) {
//                                    // TODO 当压缩过程出现问题时调用
//                                    Toast.makeText(instances, "图片压缩出现问题，请重试", Toast.LENGTH_LONG).show();
//                                }
//                            }).launch();    //启动压缩

                }
//                }
            }
        }
    }

    @Override
    public void takeFail(TResult result, String msg) {
        Log.e("tag", "拍照失败takeFail==" + msg);
        String logStr = "\n" + "外检项目拍照----拍照失败==" + "\n" + msg;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        ArrayList<TImage> images = result.getImages();
        if (images != null && images.size() > 0) {
            String photo_file_path = images.get(0).getCompressPath();
            String photo_file_path2 = images.get(0).getOriginalPath();
            Log.e("tag", "拍照失败--path==" + photo_file_path);
            Log.e("tag", "拍照失败--path=22=" + photo_file_path2);
        }
    }

    @Override
    public void takeCancel() {
        Log.e("tag", "拍照takeCancel==");
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.TPermissionType type = PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.handlePermissionsResult(this, type, invokeParam, this);
    }

    InvokeParam invokeParam;

    @Override
    public PermissionManager.TPermissionType invoke(InvokeParam invokeParam) {
        PermissionManager.TPermissionType type = PermissionManager.checkPermission(TContextWrap.of(this), invokeParam.getMethod());
        if (PermissionManager.TPermissionType.WAIT.equals(type)) {
            this.invokeParam = invokeParam;
        }
        return type;
    }

    Uri imageUri;

    void gotoRoadTakePhoto() {
        takePhoto = getTakePhoto();
//        TakePhotoOptions takePhotoOptions = new TakePhotoOptions.Builder().setCorrectImage(false).create();
//        takePhoto.setTakePhotoOptions(takePhotoOptions);
        File file = new File(Environment.getExternalStorageDirectory(), "/temp_my_app/" + System
                .currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        imageUri = Uri.fromFile(file);
        UtilsLog.e("tag", "WAIJIAN_PHOTO_imageUri=7777=" + imageUri);
//                img_imageUri_path = imageUri.getPath();
        UtilsLog.e("tag", "WAIJIAN_PHOTO_imageUri=888=" + imageUri.getPath());
        CropOptions cropOptions;  //裁剪参数
        cropOptions = new CropOptions.Builder().setAspectX(2).setAspectY(1).setWithOwnCrop(false).create();
        takePhoto.onPickFromCaptureWithCrop(imageUri, cropOptions);
//        takePhoto.onPickFromCapture(imageUri);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        getTakePhoto().onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("tag", "55555==requestCode==" + requestCode + "===resultCode===" + resultCode);
        if (data != null) {
            Log.e("tag", "666666");
        } else {
            Log.e("tag", "data=====null===");
        }
    }

    String str = "";

    public String webImage(String filePath, String access_token) {
        str = "";
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/webimage";
        try {
            // 本地文件路径
//            String filePath = "[本地文件路径]";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");
            String param = "image=" + imgParam;
            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = access_token;
            String result = HttpUtil.post(url, accessToken, param);
            String logStr = "\n" + "webImage--2---" + "\n"
                    + "\n" + "result" + result + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
            UtilsLog.e("webImage====result==" + result);
            JSONObject jsonObject = new JSONObject(result);
            if (jsonObject.has("log_id") && jsonObject.has("words_result_num")) {
                String log_id = jsonObject.getString("log_id");
                int words_result_num = jsonObject.getInt("words_result_num");
                JSONArray jsonArray = jsonObject.getJSONArray("words_result");

                if (jsonArray != null) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        str += jsonArray.optJSONObject(i).getString("words");
                    }
                    UtilsLog.e("识别结果====" + str);
                    if (currentET != null) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                currentET.setText(str);
                            }
                        });
                    }

                } else {
                    Toast.makeText(instances, "识别失败,请重试", Toast.LENGTH_LONG).show();
                }
            } else {
                UtilsLog.e("返回数据错误----识别失败");
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            String logStr = "\n" + "webImage--2---" + "\n"
                    + "\n" + "e==" + e.getMessage() + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        }
        return null;
    }

}
